from .Clike import exp
from ...comput.bitcarry import And, Or, Not, Xor, Eqv, imp
from math import log
from random import random as _random

vbCrLf: str = chr(13) + chr(10)


def iif(a: bool, b, c):
    """还原VB的三元运算符"""
    return b if a else c


def Cstr(x) -> str:
    return str(x)


def Val(x) -> float:
    return float(x)


def Rnd() -> float:
    return _random()


Asc = ord
Integer = int
Long = int
Byte = int
Boolean = bool
String = str
Single = float
Double = float


def Lcase(st: str) -> str:
    return st.lower()


def Ucase(st: str) -> str:
    return st.upper()


def string(times: int, st: str) -> str:
    """VB的String函数"""
    return '' if times < 1 or not st else ''.join(st[0] for _ in range(times))


def left(st: str, l: int) -> str:
    l = min(max(l, 0), len(st))
    return st[:l]


def right(st: str, r: int) -> str:
    r = min(max(r, 0), len(st))
    return st[len(st) - r :]


def mid(st: str, start: int, lens: int) -> str:
    start = min(max(start, 0), len(st))
    lens = min(max(lens, 0), len(st) - start)
    return st[start - 1 : start - 1 + lens]


def instr(start: int, st: str, aim: str) -> int:
    start = min(max(start, 0), len(st))
    return st[start:].find(aim)
